package com.example.sxt_practise.GOF23.composite.filekillvirus;

import java.util.ArrayList;
import java.util.List;

/**
 * @author gaofeng
 * @date 2022年05月23日 21:26
 */
public class Folder implements AbstractFile{

    private final String fileName ;

    public Folder(String fileName) {
        this.fileName = fileName;
    }

    private final List<AbstractFile> files = new ArrayList<>() ;

    public void add(AbstractFile file) {
        files.add(file) ;
    }

    public void remove(AbstractFile file) {
        files.remove(file) ;
    }

    public AbstractFile getChild(int index) {
        return files.get(index) ;
    }

    @Override
    public void killVirus() {
        System.out.println("文件夹" + fileName + "正在进行查杀!");

        for (AbstractFile file : files) {

            file.killVirus();
        }
    }
}
